package com.glsc.ngateway.common.base.repo.mysql.gateway.other;


import com.glsc.ngateway.common.base.domain.mysql.gateway.other.EmailClient;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;

public interface EmailClientRepository extends JpaRepository<EmailClient, Integer>, JpaSpecificationExecutor<EmailClient> {

    @Transactional
    @Modifying
    @Query(value = "update t_am_email_client set mail_status = :mailStatus,remark =CONCAT(IFNULL(remark,''),:moreRemark)  where mail_id = :mailId ", nativeQuery = true)
    Integer updateStatusByMailId(@Param("mailId") String mailId, @Param("mailStatus") String mailStatus, @Param("moreRemark") String moreRemark);

    @Transactional
    @Modifying
    @Query(value = "update t_am_email_client set mail_status = '3', remark = :failReason where mail_id = :mailId ", nativeQuery = true)
    Integer updateFailReasonByMailId(@Param("mailId") String mailId, @Param("failReason") String failReason);

    List<EmailClient> findAllByContentAndServiceNameAndOpTimeAfter(String content, String serviceName, LocalDateTime before);
}
